package com.xuzong.controller;

import com.rabbitmq.client.Channel;
import com.xuzong.pojo.TbCode;
import com.xuzong.pojo.TbWarehouse;
import com.xuzong.service.TbCodeService;
import com.xuzong.service.TbWarehouseService;
import com.xuzong.util.PageInfoVo;
import com.xuzong.util.R;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/warehouse/warehouse")
public class WarehouseController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    TbWarehouseService tbWarehouseService;

    @Autowired
    TbCodeService tbCodeService;


    /**
     * @description: 列表
     * @author: xushuaihang
     * @Date: 2024/8/3 9:52
     * @param:
     * @param pageInfoVo
     * @return: com.xuzong.util.R
    **/
    @RequestMapping("/warehouseList")
    public R warehouseList(@RequestBody PageInfoVo pageInfoVo){

        return tbWarehouseService.warehouseList(pageInfoVo);

    }

    /**
     * @description: 添加
     * @author: xushuaihang
     * @Date: 2024/8/3 9:53
     * @param:
     * @param tbWarehouse
     * @return: com.xuzong.util.R
    **/
    @RequestMapping("/addWarehouse")
    public R addWarehouse(@RequestBody TbWarehouse tbWarehouse){

        return tbWarehouseService.addWarehouse(tbWarehouse);

    }

    @RequestMapping("/codeList")
    public R codeList(){
        List<TbCode> list = tbCodeService.list();

        return R.ok(list);
    }

    @PostMapping("/test1")
    public void test1(){
        System.out.println("Wldlwjdlwj");
    }


//
//    @PostConstruct
//    public void initRabbitMq(){
//
//        rabbitTemplate.setReturnCallback(
//                new RabbitTemplate.ReturnCallback() {
//                    @Override
//                    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
//                        rabbitTemplate.convertAndSend(exchange,"",message);
//                    }
//                }
//        );
//        rabbitTemplate.setConfirmCallback(
//                new RabbitTemplate.ConfirmCallback() {
//                    @Override
//                    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//                        if(ack){
//                            System.out.println("发送成功！");
//                        }else {
//                            System.out.println("发送失败！");
//                        }
//                    }
//                }
//        );
//
//    }
//
//    @RequestMapping("/testRabbitMq/{id}")
//    public R testRabbitMq(@PathVariable("id") Integer id){
//
//        rabbitTemplate.convertAndSend("fanoutExchanges","",id);
//
//        return R.ok();
//    }
//
//
//    @RabbitListener(queues = "xuzong1")
//    public void PublishSubscribeQueueA(Message message, Channel channel) throws IOException {
//
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
//
//        System.out.println("xuzong1"+message);
//
//    }
//    @RabbitListener(queues = "xuzong2")
//    public void PublishSubscribeQueueB(String message){
//
//        System.out.println("xuzong2"+message);
//
//
//    }
}
